import Vue from 'vue'
import VueI18n from 'vue-i18n'

Vue.use(VueI18n)



export default ({ app, store }) => {
  // Set i18n instance on app
  // This way we can use it in middleware and pages asyncData/fetch
  app.i18n = new VueI18n({
    locale: store.state.locale,
    fallbackLocale: 'zh',
    messages: {
      en: require('~/locales/en/index.js'),
      zh: require('~/locales/zh/index.js')
    }
  })

  app.i18n.path = (link) => {
    if (app.i18n.locale === app.i18n.fallbackLocale) {
      return `/${link}`
    }

    return `/${app.i18n.locale}/${link}`
  }
  // app.i18n.changeLang = (link) => {
  //   console.log(link.replace('lang-', ''))
  //   link = link.replace('lang-', '')
  //   if (link === 'lang' || link === 'index') {
  //     link = ''
  //   }
  //   if (app.i18n.locale === 'zh') {
  //     return `/en/${link}`
  //   }
  //   return `/${link}`
  // }
}
